package com.cloud.ribbon.web;

import com.cloud.demo.pojo.User;
import com.cloud.ribbon.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;

@Controller
@RequestMapping("${version}/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("")
    public String index() {
        return "index";
    }

    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public String cardId(HashMap hashMap) {
        int userId = 1;
//        ResponseEntity<String> entity = restTemplate.getForEntity("http://user-service/v1.0/user/{userId}", String.class, userId);
//        String info = entity.getBody();
        User info = userService.getUserById(userId);
        hashMap.put("info", info);

        return "userInfo";
    }
}
